﻿namespace LogicStudio.Framework.UI.Extensiones
{
    using System.Windows;
    using System.Windows.Controls;

    /// <summary>
    /// Proporciana el atributo auxiliar TitleBinding a un objeto del tipo <see cref="DataGridColumn"/>
    /// </summary>
    public static class DataGridColumnHelper
    {
        #region Atributos

        public static readonly DependencyProperty HeaderBindingProperty = DependencyProperty.RegisterAttached(
        HeaderBinding,
        typeof(object),
        typeof(DataGridColumnHelper),
        new PropertyMetadata(null, HeaderBindingPropertyChanged));

        #endregion

        #region Constantes

        private const string HeaderBinding = "HeaderBinding";

        #endregion

        #region Métodos Privados

        private static void HeaderBindingPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var column = d as DataGridColumn;

            if (column == null) { return; }

            column.Header = e.NewValue;
        }

        #endregion

        #region Métodos Públicos

        public static object GetHeaderBinding(DependencyObject source)
        {
            return source.GetValue(HeaderBindingProperty);
        }

        public static void SetHeaderBinding(DependencyObject target, object value)
        {
            target.SetValue(HeaderBindingProperty, value);
        }

        #endregion
    }
}